//
//  LYTabbarItem.swift
//  微博
//
//  Created by liuerying on 16/5/27.

import UIKit

class LYTabbarItem: UITabBarItem {

    //重写属性
   override var badgeValue: String?{
    
    didSet{
    
        let target = valueForKey("_target")as!LYMainViewController
   
        for subView in target.tabBar.subviews {
            
            if subView.isKindOfClass(NSClassFromString("UITabBarButton")!){
                
                for v in subView.subviews{
                    
                    if v.isKindOfClass(NSClassFromString("_UIBadgeView")!){
                        
                        for bgView in v.subviews{
                            
                            if bgView.isKindOfClass(NSClassFromString("_UIBadgeBackground")!){
                                
                                print(bgView,"终于找到你,还好没放弃")
                                
                                let image = UIImage(named: "main_badge")
                                
                                bgView.setValue(image, forKey: "_image")
                            }
                        }
                        
                    }
                }
                
            }
            
        }

        
    }
        
    }
}
